﻿using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace RainwaterTankEstimator
{
    // bind this view model to your page or window (DataContext)
    public class MainChartViewModel
    {
        public ObservableCollection<TestClass> Data
        {
            get;
            set;
        }

        public MainChartViewModel(IEnumerable<ObservableCollection<Datum>> list)
        {
            Data = new ObservableCollection<TestClass>();
            Data.Add(new TestClass() { Category = "Inefficiency loss", Number = (int)list.Select(x => x[0]).Sum(x => x.Value) });
            Data.Add(new TestClass() { Category = "First flush", Number = (int)list.Select(x => x[1]).Sum(x => x.Value) });
            Data.Add(new TestClass() { Category = "Overflow", Number = (int)list.Select(x => x[2]).Sum(x => x.Value) });
            Data.Add(new TestClass() { Category = "Storage tank", Number = (int)list.Select(x => x[3]).Sum(x => x.Value) });
        }

        private object selectedItem = null;
        public object SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                // Selected item has changed
                selectedItem = value;
            }
        }
    }

    public class SecondChartViewModel
    {
        public ObservableCollection<TestClass> Data
        {
            get;
            set;
        }

        public SecondChartViewModel(List<float> list)
        {
            Data = new ObservableCollection<TestClass>();
            Data.Add(new TestClass() { Category = "> 99%", Number = list.Count(x => x > 0.99) });
            Data.Add(new TestClass() { Category = "50 - 99%", Number = list.Count(x => x <= 0.99 && x > 0.5) });
            Data.Add(new TestClass() { Category = "1 - 50%", Number = list.Count(x => x <= 0.5 && x > 0.01) });
            Data.Add(new TestClass() { Category = "< 1%", Number = list.Count(x => x <= 0.01) });
        }

        private object selectedItem = null;
        public object SelectedItem
        {
            get
            {
                return selectedItem;
            }
            set
            {
                // Selected item has changed
                selectedItem = value;
            }
        }
    }

    // class which represent a data point in the chart
    public class TestClass
    {
        public string Category { get; set; }

        public int Number { get; set; }
    }
}